package com.s2paganini.filters 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.Sprite;	

	/**
	 * @author siLvio paganini | s2paganini.com
	 * @purpose Invert Color of a Display Object
	 */

	public class InvertColor 
	{
		public static function invert(holder : Sprite) : void
		{
			if (holder.numChildren > 1) {
				holder.removeChildAt(1);
			} else {
				var img : BitmapData = new BitmapData(holder.width,holder.height);
				var bmp : Bitmap = new Bitmap(img);
				img.draw(holder.getChildAt(0));
				bmp.blendMode = BlendMode.INVERT;
				bmp.x = -bmp.width/2;
				bmp.y = -bmp.height/2;
				holder.addChild(bmp);
			}	
		}
	}
}
